package com.ruoyi.mall.app.service.impl;

import com.ruoyi.mall.app.service.DtsSearchHistoryService;
import com.ruoyi.mall.common.domain.DtsSearchHistory;
import com.ruoyi.mall.common.mapper.DtsSearchHistoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DtsSearchHistoryServiceImpl implements DtsSearchHistoryService {

    @Autowired
    private DtsSearchHistoryMapper dtsSearchHistoryMapper;

    @Override
    public List<DtsSearchHistory> selectSearchHistory(DtsSearchHistory dtsSearchHistory) {
        return dtsSearchHistoryMapper.selDtsSearchHistoryByUserId(dtsSearchHistory);
    }

    @Override
    public int addSearchHistory(DtsSearchHistory dtsSearchHistory) {
        List<DtsSearchHistory> dtsSearchHistories = dtsSearchHistoryMapper.selDtsSearchHistoryByUserId(dtsSearchHistory);
        if (dtsSearchHistories.size() > 0) {
            return 1;
        }
        return dtsSearchHistoryMapper.insertDtsSearchHistory(dtsSearchHistory);
    }

    @Override
    public int delSearchHistory(DtsSearchHistory dtsSearchHistory) {
        return dtsSearchHistoryMapper.delDtsSearchHistory(dtsSearchHistory);
    }
}
